package com.example.demo.collerct;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.Blog;
import com.example.demo.entity.Type;
import com.example.demo.service.Blogservice;
import com.example.demo.service.Typeservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class Typecollerct {
    @Autowired
    Typeservice typeservice;
    @Autowired
    Blogservice blogservice;

    @RequestMapping("/totype")
    public  String km(Model model, @RequestParam(defaultValue = "1") Integer pageIndex){
        Page<Type> page = new Page<>(pageIndex,3);
       model.addAttribute("page",typeservice.selecrA(page));

        return "admin/types";
    }
    @RequestMapping("/insertType")
    public String ap(){
        return "admin/types-input";
    }
    @RequestMapping("/insertTypea")
    public String apa(Type type,Model model){
        int insert = typeservice.insert(type);
        return "forward:totype";
    }
    @RequestMapping("/toupdateTypea")
    public String apatoUpdate(int id,Model model){
        Type sele = typeservice.sele(id);
        model.addAttribute("types",sele);
        return "admin/types-input";
    }
    @RequestMapping("/updateTypea")
    public  String updateTy(Type type){
        int update = typeservice.update(type);

        return "forward:totype";
    }
    @ResponseBody
    @RequestMapping("/dateType")
    public Object ala(int id){
        Map<String,String> map = new HashMap<>();
        int  sel = blogservice.sel(id);
        if (sel==0){
            int date = typeservice.date(id);
            System.out.println(date);
        }else {
            map.put("msg","没有");
        }
    return map;
    }
}
